package cc.fs.myproject.Adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cc.fs.myproject.R;

/**
 * Created by fostion on 2015/6/17.
 */
public class DataAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final int FOOTER = 0;
    private final int ITEM = 1;

    private Context context;
    private List<String> list;
    private LayoutInflater layoutInflater;
    private boolean isLoadingMore;

    public DataAdapter(Context context){
        this.context = context;
        list = new ArrayList<String>();
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        layoutInflater = LayoutInflater.from(context);
        isLoadingMore = true;
    }

    @Override
    public int getItemCount() {
        return isLoadingMore? list.size()+1:list.size();
    }

    @Override
    public int getItemViewType(int position) {
        if(position == list.size() && isLoadingMore) return FOOTER;
        return  ITEM;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {

        View v = null;
        if(viewType == FOOTER){
            v = layoutInflater.inflate(R.layout.view_footer_loadingmore,viewGroup,false);
            return  new FooterHolder(v);
        }

        if(viewType == ITEM){
            v = layoutInflater.inflate(R.layout.item_data,viewGroup,false);
            return  new ItemHolder(v);
        }

        throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

    }

    public void setLoadingMore(boolean isLoadingMore){
        this.isLoadingMore = isLoadingMore;
    }


    class ItemHolder extends RecyclerView.ViewHolder{

        public ItemHolder(View itemView) {
            super(itemView);
        }
    }

    class FooterHolder extends RecyclerView.ViewHolder{

        public FooterHolder(View itemView) {
            super(itemView);
        }
    }
}
